<?php
namespace Library\Components\Task;

use Library\Redis\RedisManager;

abstract class DelayTask
{
    const DELAY_TASK = 'delayTask';

    /**
     * 延时时间, 在触发后多久执行
     * @param int $pushDelayTime
     */
    public function startAfter(int $pushDelayTime)
    {
        RedisManager::getRedis()->zAdd(self::DELAY_TASK, time() + $pushDelayTime, serialize($this));
    }

    /**
     * 定时时间, 在未来某时刻执行
     */
    public function startAt(int $pushDelayAt)
    {
        RedisManager::getRedis()->zAdd(self::DELAY_TASK, $pushDelayAt, serialize($this));
    }

    abstract function run();
}